package com.net.oil.TechnologySupport;

import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.net.oil.R;
import com.net.oil.TechnologySupport.bean.TechnologyListBean;
import com.net.oil.app.Constant;
import com.net.oil.util.StringUtil;
import com.net.oil.util.WebViewUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TechnologyDetailActivity extends AppCompatActivity {

    @BindView(R.id.toolbar_go_back)
    ImageView toolbarGoBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.web_view)
    WebView webView;

    private static String mimeType = "text/html";
    private static String encoding = "UTF-8";

    private WebSettings webSetting;
    private TechnologyListBean.ListBean technology;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_technology_detail);
        ButterKnife.bind(this);

        initView();
        initData();
    }

    private void initData() {
        Intent intent = getIntent();
        technology = (TechnologyListBean.ListBean) intent.getSerializableExtra(Constant.INTENT_TECHNOLOGY_KEY);
        if (technology != null) {
            if (!StringUtil.isEmpty(technology.getContent())) {
//                webView.loadDataWithBaseURL(null, technology.getContent(), mimeType, encoding, null);

                webView.loadData(WebViewUtil.getHtmlData(technology.getContent()), "text/html; charset=UTF-8", null);
            }
        }

    }

    private void initView() {
        toolbarTitle.setText("详情");
        webSetting = webView.getSettings();
        webSetting.setTextZoom(100);
        webSetting.setJavaScriptEnabled(true);
        webSetting.setUseWideViewPort(true);  //将图片调整到适合webview的大小
        webSetting.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
    }

    @OnClick(R.id.toolbar_go_back)
    public void onViewClicked() {
        finish();
    }

}
